<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Contact extends CI_Controller {

    function index() {
        $data_welcome['title'] = "Hionidis Kostas Paintings Website - 
        Contact";
        $data_welcome['description'] = "
           Kostas Hionidis contact page.
           ";
        $this->load->helper(array('form', 'url', 'html', 'captcha'));
        $this->load->library('form_validation');
        $this->form_validation->set_rules('name', 'Name', 'trim|xss_clean');
        $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|valid_email');
        $this->form_validation->set_rules('website', 'Website', 'trim|xss_clean');
        $this->form_validation->set_rules('title', 'Title', 'trim|xss_clean');
        $this->form_validation->set_rules('message', 'Submit the word you see below', 'required|trim|xss_clean');
        $this->form_validation->set_rules('captcha', 'captcha', 'required');

        if ($this->form_validation->run() == FALSE) {
            $this->load->view('welcome_view',$data_welcome);
            $this->load->view('contact_form_view');
            $this->load->view('footer');
        } else {
            $ToEmail = 'john@echidna-band.com';
            $ToEmail_admin = 'ichionid@gmail.com';
            $EmailSubject = '[Contact From Hionidis Artistic Website]' . $_POST["title"];
            $mailheader = "From: " . $_POST["email"] . "\r\n";
            $mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";
            $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
            $MESSAGE_BODY = "Name: " . $_POST["name"] . "<br>";
            $MESSAGE_BODY .= "Email: " . $_POST["email"] . "<br>";
            $MESSAGE_BODY .= "message: " . nl2br($_POST["message"]) . "<br>";
            mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
            mail($ToEmail_admin, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
            redirect('/contact/success', 'refresh');
        }
    }
    function success() {

        $this->load->helper(array('form', 'url', 'html', 'captcha'));
        $this->load->library('form_validation');
        $data_welcome['title'] = "Hionidis Kostas Paintings Website - 
        Contact";
        $data_welcome['description'] = "
           Kostas Hionidis contact page.
           ";
        $this->form_validation->set_rules('name', 'Name', 'trim|xss_clean');
        $this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|valid_email');
        $this->form_validation->set_rules('website', 'Website', 'trim|xss_clean');
        $this->form_validation->set_rules('title', 'Title', 'trim|xss_clean');
        $this->form_validation->set_rules('message', 'Submit the word you see below', 'required|trim|xss_clean');
        $this->form_validation->set_rules('captcha', 'captcha', 'required');

        if ($this->form_validation->run() == FALSE) {
            //success
            $this->load->view('welcome_view',$data_welcome);
            $this->load->view('contact_form_view_success');
            $this->load->view('footer');
        } else {
            //submit
            $ToEmail = 'john@echidna-band.com';
            $ToEmail_admin = 'ichionid@gmail.com';
            $EmailSubject = '[Contact From Hionidis Artistic Website]' . $_POST["title"];
            $mailheader = "From: " . $_POST["email"] . "\r\n";
            $mailheader .= "Reply-To: " . $_POST["email"] . "\r\n";
            $mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
            $MESSAGE_BODY = "Name: " . $_POST["name"] . "<br>";
            $MESSAGE_BODY .= "Email: " . $_POST["email"] . "<br>";
            $MESSAGE_BODY .= "message: " . nl2br($_POST["message"]) . "<br>";
            mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
            mail($ToEmail_admin, $EmailSubject, $MESSAGE_BODY, $mailheader) or die("Failure");
            redirect('/contact/success', 'refresh');
        }
    }

}